#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "plugin.h"

static struct plugin *plugin_t;

void handle_msg( char *msg ) 
{
	char *subs;

	printf("Simple plugin received: %s\n", msg );

	if ( (subs = strstr( msg, "PRIVMSG" )) != NULL ) {
		if ( (subs = strstr( subs, "llamabot" )) != NULL ) {
			printf("Some one called me? \n");
			plugin_t->send_message("PRIVMSG #homeopathcs :it's me ;) \n");
		}		
	}
 
}

struct plugin * new_plugin() 
{
	plugin_t = (struct plugin*) malloc( sizeof( struct plugin ) );
	if ( plugin_t == NULL ) {
		fprintf( stderr, "Simple plugin allocation failed, out of memory. \n" );		
		return NULL;
	}

	plugin_t->id = "Simple plugin";
	plugin_t->handle_msg = handle_msg;

	return plugin_t;
}

/* TODO delete_plugin function and make sure that all allocated memory will be freeded
   One would like to use gcc function attributes constructor and destructor as well*/
